﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using StyleMVVM.DependencyInjection.Impl;

namespace StyleMVVM.DependencyInjection
{
	/// <summary>
	/// This attribute is meant to go on public properties and denotes that 
	/// as part of activation process this property should be populated from the container
	/// </summary>
	[AttributeUsage(AttributeTargets.Property | AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)]
	public class ImportAttribute : Attribute, IImportAttribute
	{
		public ImportAttribute()
		{
			Required = true;
		}

		/// <summary>
		/// This is the name to use when resolving an import. when null the type of the property is used for Dependency Injection location
		/// </summary>
		public string ImportName { get; set; }

		/// <summary>
		/// If true then construction will fail if import cannot be found. (true by default)
		/// </summary>
		public bool Required { get; set; }

		/// <summary>
		/// If true this property will be resolved everytime rather than resolved once at startup.
		/// This property does not effect if the import will be shared only if it will be resolved each time.
		/// </summary>
		public bool Volatile { get; set; }

		/// <summary>
		/// Returns information about how to import the property. Must not return null
		/// </summary>
		/// <param name="memberInfo"></param>
		/// <returns></returns>
		public IImportAttributeInfo ProvideImportInfo(object memberInfo)
		{
			return new ImportAttributeInfo { ImportName = ImportName, Required = Required, Volatile = Volatile };
		}
	}
}